#include "stdafx.h"
#include "Army.h"
#include "config.h"
#include "Scene.h"
#include "ObjectManager.h"

sgObject * sgArmy::Creator()
{
    return new sgArmy;
}

bool sgArmy::m_creatorRegisted = CObjectManager::Instance().RegisteCreator(OBJ_ARMY, sgArmy::Creator );

sgArmy::sgArmy( int type )
{
    m_type = type;
}

sgArmy::~sgArmy()
{

}

bool sgArmy::Initialize()
{
    bool ret = sgEntity::Initialize();
    m_layer = eLayer_Army;
    const ArmyEntry *entry = Config::Instance().GetArmyEntry( m_type );
    CHECK_PTR(entry, false);
    m_entry = *entry;
    m_animation.Initialize( MBToWChar(entry->animName.c_str()) );
    m_animation.StartAnim( L"Stand" );
    return ret;
}

ArmyEntry & sgArmy::GetEntry()
{
    return m_entry;
}

sgArmy * sgArmy::Clone()
{
    sgArmy *ret = new sgArmy( m_type );
    ret->Initialize();
    ret->SetPosition( m_position );
    ret->m_entry = m_entry;
    ret->SetOwner( m_owner );
    return ret;
}

void sgArmy::Serialize( CSerialize& s )
{
    sgForceEntity::Serialize(s);
    s&MAKE_PAIR(m_type,"type");
    s&MAKE_PAIR(m_entry.movespeed,"movespeed");
    m_layer = eLayer_Army;
    m_animation.Initialize( MBToWChar(m_entry.animName.c_str()) );
    m_animation.StartAnim( L"Stand" );
}
